Change in openvpn[master]: Remove various redundant conditionals
A message that is not in the archive (sent off-list or not yet received): gerrit.1775421558000.Iacf06c113e8db5b7c78270f361ee76938ef1db47@...2715...
Attention is currently required from: plaisthos.
Hello plaisthos,
I'd like you to do a code review.
Please visit
http://gerrit.openvpn.net/c/openvpn/+/1613?usp=email
to review the following change.
Change subject: Remove various redundant conditionals
......................................................................
Remove various redundant conditionals
These are all already proven to be true by
surrounding code.
Identified by cppcheck.
---
M src/openvpn/manage.c
M src/openvpn/multi.c
M src/openvpn/options.c
M src/openvpn/platform.c
M src/openvpn/ssl_verify.c
M src/openvpnserv/interactive.c
6 files changed, 8 insertions(+), 11 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/13/1613/1
src/openvpn/manage.c +2 -5
@@ -1551,10 +1551,7 @@ }else { -if (p[1 ]) - { -man_state (man, p[1 ]); - } +man_state (man, p[1 ]);if (p[2 ]) {man_state (man, p[2 ]);
@@ -2457,7 +2454,7 @@ {buffer_list_advance (man->connection.out, sent); } - else if (sent < 0) + else {if (man_io_error (man,"send" )) {
src/openvpn/multi.c +1 -1
@@ -1869,7 +1869,7 @@ {msg (M_INFO ,"PUSH: No NCP or OCC cipher data received from peer." ); -if (o->enable_ncp_fallback && !tls_multi->remote_ciphername) +if (o->enable_ncp_fallback) {msg (M_INFO , "Using data channel cipher '%s' since "
src/openvpn/options.c +1 -1
@@ -5304,7 +5304,7 @@struct dns_server *server =dns_server_get (&options->dns_options.servers, priority, &options->dns_options.gc); -if (streq (p[3 ],"address" ) && p[4 ]) +if (streq (p[3 ],"address" )) {for (int i =4 ; p[i]; ++i) {
src/openvpn/platform.c +1 -1
@@ -572,7 +572,7 @@close (fd);return retfname; } -else if (fd ==-1 && errno !=EEXIST ) +else if (errno !=EEXIST ) {/* Something else went wrong, no need to retry. */ msg (M_WARN |M_ERRNO ,"Could not create temporary file '%s'" , retfname);
src/openvpn/ssl_verify.c +1 -1
@@ -895,7 +895,7 @@ {/* Must have at least three lines. further lines are ignored for * forward compatibility */ -if (!lines->head || !lines->head->next || !lines->head->next->next) +if (!lines->head->next || !lines->head->next->next) {msg (M_WARN ,"auth pending control file is not at least " "three lines long." );
src/openvpnserv/interactive.c +2 -2
@@ -486,7 +486,7 @@ sud->directory = data; len =wcslen (sud->directory) +1 ; size -= len; -if (size <=0 ) +if (size ==0 ) {MsgToEventLog (M_ERR ,L"Startup data ends at working directory" );ReturnError (pipe,ERROR_STARTUP_DATA ,L"GetStartupData" ,1 , &exit_event);
@@ -496,7 +496,7 @@ sud->options = sud->directory + len; len =wcslen (sud->options) +1 ; size -= len; -if (size <=0 ) +if (size ==0 ) {MsgToEventLog (M_ERR ,L"Startup data ends at command line options" );ReturnError (pipe,ERROR_STARTUP_DATA ,L"GetStartupData" ,1 , &exit_event);
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1613?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iacf06c113e8db5b7c78270f361ee76938ef1db47
Gerrit-Change-Number: 1613
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Attention is currently required from: flichtenheld, plaisthos.
cron2 has posted comments on this change by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1613?usp=email )
Change subject: Remove various redundant conditionals
......................................................................
Patch Set 3: Code-Review+2
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1613?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iacf06c113e8db5b7c78270f361ee76938ef1db47
Gerrit-Change-Number: 1613
Gerrit-PatchSet: 3
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Sun, 19 Apr 2026 13:51:03 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
PATCH v3 1/1 Remove various redundant conditionals
In reply to a message not in the archiveFrom: Frank Lichtenheld <[email protected]...>
These are all already proven to be true by
surrounding code.
Identified by cppcheck.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1613
---
This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1613
This mail reflects revision 3 of this Change.
Acked-by according to Gerrit (reflected above):
Gert Doering <[email protected]...>
src/openvpn/manage.c +2 -5
@@ -1625,10 +1625,7 @@ }else { -if (p[1 ]) - { -man_state (man, p[1 ]); - } +man_state (man, p[1 ]);if (p[2 ]) {man_state (man, p[2 ]);
@@ -2542,7 +2539,7 @@ {buffer_list_advance (man->connection.out, sent); } - else if (sent < 0) + else {if (man_io_error (man,"send" )) {
src/openvpn/multi.c +1 -1
@@ -1837,7 +1837,7 @@ {msg (M_INFO ,"PUSH: No NCP or OCC cipher data received from peer." ); -if (o->enable_ncp_fallback && !tls_multi->remote_ciphername) +if (o->enable_ncp_fallback) {msg (M_INFO , "Using data channel cipher '%s' since "
src/openvpn/options.c +1 -1
@@ -5304,7 +5304,7 @@struct dns_server *server =dns_server_get (&options->dns_options.servers, priority, &options->dns_options.gc); -if (streq (p[3 ],"address" ) && p[4 ]) +if (streq (p[3 ],"address" )) {for (int i =4 ; p[i]; ++i) {
src/openvpn/platform.c +1 -1
@@ -572,7 +572,7 @@close (fd);return retfname; } -else if (fd ==-1 && errno !=EEXIST ) +else if (errno !=EEXIST ) {/* Something else went wrong, no need to retry. */ msg (M_WARN |M_ERRNO ,"Could not create temporary file '%s'" , retfname);
src/openvpn/ssl_verify.c +1 -1
@@ -895,7 +895,7 @@ {/* Must have at least three lines. further lines are ignored for * forward compatibility */ -if (!lines->head || !lines->head->next || !lines->head->next->next) +if (!lines->head->next || !lines->head->next->next) {msg (M_WARN ,"auth pending control file is not at least " "three lines long." );
src/openvpnserv/interactive.c +2 -2
@@ -486,7 +486,7 @@ sud->directory = data; len =wcslen (sud->directory) +1 ; size -= len; -if (size <=0 ) +if (size ==0 ) {MsgToEventLog (M_ERR ,L"Startup data ends at working directory" );ReturnError (pipe,ERROR_STARTUP_DATA ,L"GetStartupData" ,1 , &exit_event);
@@ -496,7 +496,7 @@ sud->options = sud->directory + len; len =wcslen (sud->options) +1 ; size -= len; -if (size <=0 ) +if (size ==0 ) {MsgToEventLog (M_ERR ,L"Startup data ends at command line options" );ReturnError (pipe,ERROR_STARTUP_DATA ,L"GetStartupData" ,1 , &exit_event);
[Openvpn-devel] [PATCH applied] Re: Remove various redundant conditionals
Verified each of the finding by staring at the code for long enough :-) - the interactive.c one gave me a bit of headache, trying to understand why it can never underrun (I'm fully in the "check with 'if (thing <= 0)' to be guarded against miscalculations" camp). Well, it cannot, because we have a size_t here, so cppcheck is very obviously right - but the code itself also ensures that we have a 0-byte at the end, and thus wcslen() can never "escape" the boundaries of "size".
Out they go... test compiled on mingw. And BB all green, of course.
Your patch has been applied to the master branch.
commit 22062deb5dc04670b48511580d576df3c4682b2e
Author: Frank Lichtenheld Date: Sun Apr 19 15:51:11 2026 +0200
Remove various redundant conditionals
Signed-off-by: Frank Lichtenheld <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1613
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg36666.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
cron2 has uploaded a new patch set (#4) to the change originally created by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1613?usp=email )
The following approvals got outdated and were removed:
Code-Review+2 by cron2
Change subject: Remove various redundant conditionals
......................................................................
Remove various redundant conditionals
These are all already proven to be true by
surrounding code.
Identified by cppcheck.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1613
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg36666.html
---
M src/openvpn/manage.c
M src/openvpn/multi.c
M src/openvpn/options.c
M src/openvpn/platform.c
M src/openvpn/ssl_verify.c
M src/openvpnserv/interactive.c
6 files changed, 8 insertions(+), 11 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/13/1613/4
src/openvpn/manage.c +2 -5
@@ -1625,10 +1625,7 @@ }else { -if (p[1 ]) - { -man_state (man, p[1 ]); - } +man_state (man, p[1 ]);if (p[2 ]) {man_state (man, p[2 ]);
@@ -2542,7 +2539,7 @@ {buffer_list_advance (man->connection.out, sent); } - else if (sent < 0) + else {if (man_io_error (man,"send" )) {
src/openvpn/multi.c +1 -1
@@ -1837,7 +1837,7 @@ {msg (M_INFO ,"PUSH: No NCP or OCC cipher data received from peer." ); -if (o->enable_ncp_fallback && !tls_multi->remote_ciphername) +if (o->enable_ncp_fallback) {msg (M_INFO , "Using data channel cipher '%s' since "
src/openvpn/options.c +1 -1
@@ -5304,7 +5304,7 @@struct dns_server *server =dns_server_get (&options->dns_options.servers, priority, &options->dns_options.gc); -if (streq (p[3 ],"address" ) && p[4 ]) +if (streq (p[3 ],"address" )) {for (int i =4 ; p[i]; ++i) {
src/openvpn/platform.c +1 -1
@@ -572,7 +572,7 @@close (fd);return retfname; } -else if (fd ==-1 && errno !=EEXIST ) +else if (errno !=EEXIST ) {/* Something else went wrong, no need to retry. */ msg (M_WARN |M_ERRNO ,"Could not create temporary file '%s'" , retfname);
src/openvpn/ssl_verify.c +1 -1
@@ -906,7 +906,7 @@ {/* Must have at least three lines. further lines are ignored for * forward compatibility */ -if (!lines->head || !lines->head->next || !lines->head->next->next) +if (!lines->head->next || !lines->head->next->next) {msg (M_WARN ,"auth pending control file is not at least " "three lines long." );
src/openvpnserv/interactive.c +2 -2
@@ -486,7 +486,7 @@ sud->directory = data; len =wcslen (sud->directory) +1 ; size -= len; -if (size <=0 ) +if (size ==0 ) {MsgToEventLog (M_ERR ,L"Startup data ends at working directory" );ReturnError (pipe,ERROR_STARTUP_DATA ,L"GetStartupData" ,1 , &exit_event);
@@ -496,7 +496,7 @@ sud->options = sud->directory + len; len =wcslen (sud->options) +1 ; size -= len; -if (size <=0 ) +if (size ==0 ) {MsgToEventLog (M_ERR ,L"Startup data ends at command line options" );ReturnError (pipe,ERROR_STARTUP_DATA ,L"GetStartupData" ,1 , &exit_event);
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1613?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iacf06c113e8db5b7c78270f361ee76938ef1db47
Gerrit-Change-Number: 1613
Gerrit-PatchSet: 4
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/1613?usp=email )
Change subject: Remove various redundant conditionals
......................................................................
Remove various redundant conditionals
These are all already proven to be true by
surrounding code.
Identified by cppcheck.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1613
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg36666.html
---
M src/openvpn/manage.c
M src/openvpn/multi.c
M src/openvpn/options.c
M src/openvpn/platform.c
M src/openvpn/ssl_verify.c
M src/openvpnserv/interactive.c
6 files changed, 8 insertions(+), 11 deletions(-)
src/openvpn/manage.c +2 -5
@@ -1625,10 +1625,7 @@ }else { -if (p[1 ]) - { -man_state (man, p[1 ]); - } +man_state (man, p[1 ]);if (p[2 ]) {man_state (man, p[2 ]);
@@ -2542,7 +2539,7 @@ {buffer_list_advance (man->connection.out, sent); } - else if (sent < 0) + else {if (man_io_error (man,"send" )) {
src/openvpn/multi.c +1 -1
@@ -1837,7 +1837,7 @@ {msg (M_INFO ,"PUSH: No NCP or OCC cipher data received from peer." ); -if (o->enable_ncp_fallback && !tls_multi->remote_ciphername) +if (o->enable_ncp_fallback) {msg (M_INFO , "Using data channel cipher '%s' since "
src/openvpn/options.c +1 -1
@@ -5304,7 +5304,7 @@struct dns_server *server =dns_server_get (&options->dns_options.servers, priority, &options->dns_options.gc); -if (streq (p[3 ],"address" ) && p[4 ]) +if (streq (p[3 ],"address" )) {for (int i =4 ; p[i]; ++i) {
src/openvpn/platform.c +1 -1
@@ -572,7 +572,7 @@close (fd);return retfname; } -else if (fd ==-1 && errno !=EEXIST ) +else if (errno !=EEXIST ) {/* Something else went wrong, no need to retry. */ msg (M_WARN |M_ERRNO ,"Could not create temporary file '%s'" , retfname);
src/openvpn/ssl_verify.c +1 -1
@@ -906,7 +906,7 @@ {/* Must have at least three lines. further lines are ignored for * forward compatibility */ -if (!lines->head || !lines->head->next || !lines->head->next->next) +if (!lines->head->next || !lines->head->next->next) {msg (M_WARN ,"auth pending control file is not at least " "three lines long." );
src/openvpnserv/interactive.c +2 -2
@@ -486,7 +486,7 @@ sud->directory = data; len =wcslen (sud->directory) +1 ; size -= len; -if (size <=0 ) +if (size ==0 ) {MsgToEventLog (M_ERR ,L"Startup data ends at working directory" );ReturnError (pipe,ERROR_STARTUP_DATA ,L"GetStartupData" ,1 , &exit_event);
@@ -496,7 +496,7 @@ sud->options = sud->directory + len; len =wcslen (sud->options) +1 ; size -= len; -if (size <=0 ) +if (size ==0 ) {MsgToEventLog (M_ERR ,L"Startup data ends at command line options" );ReturnError (pipe,ERROR_STARTUP_DATA ,L"GetStartupData" ,1 , &exit_event);
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1613?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iacf06c113e8db5b7c78270f361ee76938ef1db47
Gerrit-Change-Number: 1613
Gerrit-PatchSet: 4
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>